<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript">
  </script>
 </head>
 <body>
  <t:formvalid formid="formobj" dialog="true" layout="table" beforeSubmit="validateInput()" 
  	action="ScoreManageController.do?saveScoreWeight" tiptype="3" >
  		<input type="hidden" name="id" value="${lessonInfo.id}">
		<table style="" cellpadding="0" cellspacing="1" class="formtable"> 
				<tr>
					<td align="right">
						<label class="Validform_label">项目1名称：</label>
					</td>
					<td class="value">
				     	<input name="scoreItem1Name" id="scoreItem1Name" value="${lessonInfo.scoreItem1Name }" type="text" style="width: 150px" class="inputxt"  >
						<span class="Validform_checktip"></span>						
					</td>
				</tr>				
				<tr>
					<td align="right">
						<label class="Validform_label">	项目1成绩比例：</label>
					</td>
					<td class="value">
					    <input  id="scoreItem1Weight" name="scoreItem1Weight"  value="${lessonInfo.scoreItem1Weight }" type="text" style="width: 150px" class="inputxt">
						<span class="Validform_checktip"></span>						
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">项目2名称：</label>
					</td>
					<td class="value">
				     	<input name="scoreItem2Name" id="scoreItem2Name" value="${lessonInfo.scoreItem2Name }" type="text" style="width: 150px" class="inputxt"  >
						<span class="Validform_checktip"></span>						
					</td>
				</tr>				
				<tr>
					<td align="right">
						<label class="Validform_label">	项目2成绩比例：</label>
					</td>
					<td class="value">
					    <input  id="scoreItem2Weight" name="scoreItem2Weight" value="${lessonInfo.scoreItem2Weight }" type="text" style="width: 150px" class="inputxt">
						<span class="Validform_checktip"></span>						
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">项目3名称：</label>
					</td>
					<td class="value">
				     	<input name="scoreItem3Name" id="scoreItem3Name" value="${lessonInfo.scoreItem3Name }" type="text" style="width: 150px" class="inputxt"  >
						<span class="Validform_checktip"></span>						
					</td>
				</tr>				
				<tr>
					<td align="right">
						<label class="Validform_label">	项目3成绩比例：</label>
					</td>
					<td class="value">
					    <input  id="scoreItem3Weight" name="scoreItem3Weight" value="${lessonInfo.scoreItem3Weight }" type="text" style="width: 150px" class="inputxt">
						<span class="Validform_checktip"></span>						
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">项目4名称：</label>
					</td>
					<td class="value">
				     	<input name="scoreItem4Name" id="scoreItem4Name" value="${lessonInfo.scoreItem4Name }" type="text" style="width: 150px" class="inputxt"  >
						<span class="Validform_checktip"></span>						
					</td>
				</tr>				
				<tr>
					<td align="right">
						<label class="Validform_label">	项目4成绩比例：</label>
					</td>
					<td class="value">
					    <input  id="scoreItem4Weight" name="scoreItem4Weight" value="${lessonInfo.scoreItem4Weight }" type="text" style="width: 150px" class="inputxt">
						<span class="Validform_checktip"></span>						
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">项目5名称：</label>
					</td>
					<td class="value">
				     	<input name="scoreItem5Name" id="scoreItem5Name" value="${lessonInfo.scoreItem5Name }" type="text" style="width: 150px" class="inputxt"  >
						<span class="Validform_checktip"></span>						
					</td>
				</tr>				
				<tr>
					<td align="right">
						<label class="Validform_label">	项目5成绩比例：</label>
					</td>
					<td class="value">
					    <input  id="scoreItem5Weight" name="scoreItem5Weight" value="${lessonInfo.scoreItem5Weight }" type="text" style="width: 150px" class="inputxt">
						<span class="Validform_checktip"></span>						
					</td>
				</tr>
			</table>
		</t:formvalid>
		<script>
			$(document).ready(function(){
				moneyValidate("weight1");
				moneyValidate("weight2");
				moneyValidate("weight3");
				moneyValidate("weight4");
				moneyValidate("weight5");
			});
		

			//进行校验
			function validateInput(){
				var name1 = $('#scoreItem1Name').val();
				var weight1 = $('#scoreItem1Weight').val();
				var name2 = $('#scoreItem2Name').val();
				var weight2 = $('#scoreItem2Weight').val();
				var name3 = $('#scoreItem3Name').val();
				var weight3 = $('#scoreItem3Weight').val();
				var name4 = $('#scoreItem4Name').val();
				var weight4 = $('#scoreItem4Weight').val();
				var name5 = $('#scoreItem5Name').val();
				var weight5 = $('#scoreItem5Weight').val();
			
				//校验是否都没有填写
				if(isNull(name1,weight1)&&isNull(name2,weight2)&&isNull(name3,weight3)
						&&isNull(name4,weight4)&&isNull(name5,weight5)){
					tip("请至少填写一项分数比例");
					return false;
				}
				
				//校验项目数至少填写一对
				if(isNotFinish(1,name1,weight1))return false;
				if(isNotFinish(2,name2,weight2))return false;
				if(isNotFinish(3,name3,weight3))return false;
				if(isNotFinish(4,name4,weight4))return false;
				if(isNotFinish(5,name5,weight5))return false;
			
				//校验总和是否为1
				var total = 0;
				if(weight1 != '') total += parseFloat(weight1);
				if(weight2 != '') total += parseFloat(weight2);
				if(weight3 != '') total += parseFloat(weight3);
				if(weight4 != '') total += parseFloat(weight4);
				if(weight5 != '') total += parseFloat(weight5);
				
				if(total > 1){
					tip('成绩比例之和不能大于1');
					return false;
				}else if(total < 1){
					tip('成绩比例之和不能小于1');
					return false;
				}else{
					return true;
				}
			}
			
			//判断是否为空
			function isNull(field1,field2){
				if(field1 == '' && field2==''){
					return true;
				}else{
					return false;
				}
			}
			
			//项目和分数比例是否有一个没有进行设置
			function isNotFinish(index,f1,f2){
				if(f1 !='' && f2==''){
					tip("请填写项目"+index+"的分数比例");
					return true;
				}else if(f1 =='' && f2 != ''){
					tip("请填写项目"+index+"的名称");
					return true;
				}else{
					return false;
				}
			}
			
		</script>
 </body>